import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:uri_to_file/src/uri_to_file_method_channel.dart';
import 'dart:io';

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();

  MethodChannelUriToFile platform = MethodChannelUriToFile();
  const MethodChannel channel = MethodChannel('in.lazymanstudios.uritofile/helper');

  setUp(() {
    TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
      channel,
      (MethodCall methodCall) async {
        if (methodCall.method == 'fromUri') {
          return '/dummy/path/file.txt';
        }
        return null;
      },
    );
  });

  tearDown(() {
    TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(channel, null);
  });

  test('isUriSupported - content uri', () {
    expect(platform.isUriSupported('content://media/external/images/media/123'), isTrue);
  });

  test('isUriSupported - non-content uri', () {
    expect(platform.isUriSupported('file:///path/to/file.txt'), isFalse);
  });

  test('toFile - mock method call', () async {
    final file = await platform.toFile('content://media/external/images/media/123');
    expect(file.path, '/dummy/path/file.txt');
  });

  test('clearTemporaryFiles - should not throw', () async {
    expect(platform.clearTemporaryFiles(), completes);
  });
}
